Learn how to integrate WebGL in a game using tools from the Sequence Stack to earn achievements and use custom ERC1155’s.
three
, all compiled using webpack
Template WebGL JS Web SDK Starter
Clone the above repo down, cd
into the repo with cd template-webgl-js-sequence-kit-starter
.env
.env
file (using the .env.example
) with the environment variables
App.jsx
Componentsrc
folder called react
and create 2 files: App.jsx
and Login.jsx
In App.jsx
include the following code
Login.jsx
file add the following code in order to create a button at the top of the screen to login to the application
index.js
index.js
import the App.jsx
component, and render it to be appended to the root
id element in index.html
Login.jsx
component
index.js
index.html
Minter Role
We will allow there to be multiple paths to mint collectibles: a plane collectible and an achievement collectible.
This is accomplished in the code by adding a key/value of isPlane
to the normal cloudflare request body, and creating an additional if/else
in the cloudflare worker.
You can view the code for this in this github repository
For this guide, we will be running all cloudflare code in a local dev envivronment, which can be accomplished by starting the cloudflare worker in the named project folder, with:
index.js
we include a button attached to the onclick
attribute of the element in index.html
callContract
takes care of the minting by calling a fetch that is wrapped in a mutex to ensure 1 mint happens at a time, to prevent click mashers, added to the SequenceController
class in /API/SequenceController.js
fetchPlaneTokens
will poll on the result until there’s an asset in your wallet, updating the plane color
to represent a different plane.
fetchPlaneTokens
is implemented with the following code, where the balance conditional check is greater than 1, and the tokenID
is equal to the searched for id.
This UI conditional logic would change based on your application
burn achievement
button, based on if the user has an achievement or not
First, implement the similiar html/js click handler logic like before
where this time, the isPlane
value of callContract
is set to false
fetchTokensFromAchievementMint
which is added to the SequenceController
display
attribute make the button appear
msg.sender
in the contract one of the relayer
addresses) for this, we want to make sure the msg.sender
in the contract proves ownership of the token, and is sent directly from the user
. We’ll use wagmi
frontend functions as well as some class composition to accomplish this.
burnToken
is a passed in function from our react component that uses the similiar pattern of using mutexes, and we send the transaction using sendTransaction
from the wagmi
package, and wait for a transaction hash update to return the callback
SequenceController
, call the sendBurnToken
function wrapped in burnToken
to make the react function accessible to the rest of the application
SequenceController
wagmi
, since rewarding achievement tokens and minting collectibles are completed using a cloudflare worker for gasless transactions.
This can be accomplished by adding a few environment variables, and switching the type of connector we use.
First update your .env
file with the following environment secrets
App.jsx